﻿var index = 0;

$("#poll_result").live('click', function(event) 
{
    event.preventDefault();

    $("#poll").load("/polls/result", { id: $("#PollId").val() });
    
    return false;
});

$("#submit_poll_choice").live('click', function(event) 
{
    event.preventDefault();
    
    var value = $("#Choice").val();

    value = jQuery.trim(value);
    
    if (value == "") 
    {
        return alert("You must enter a value");
    }

    $("#poll_choices").find('tbody')
            .append($('<tr>')
                .append($('<td>').addClass("title")
                    .append($('<input>').attr('type', 'text').attr('id', 'Choices[' + index + ']').attr('name', 'Choices[' + index + ']').attr('size', '30').val(value)))
                .append($('<td>').addClass("delete")
                    .append($('<a>').addClass('delete-poll-choice').attr('href', '#choices').text('Delete'))));

    index++;

    $("#Choice").val("");

    return false;
});

$(".delete-poll-choice").live('click', function(event) 
{
    $(this).parent().parent().remove();
    
    index--;

    return false;
});